﻿using il.lua;

public class CallExpression : Expression
{
    private readonly MethodReference _method;
    private readonly Expression[] _arguments;

    public MethodReference Method => _method;
    public Expression[] Arguments => _arguments;

    public CallExpression(MethodReference method, params Expression[] arguments)
    {
        _method = method;
        _arguments = arguments;
    }

    public override void Print()
    {
        ConsoleEx.Code($"{_method.DeclaringType.FullName}.{_method.Name}");
        ConsoleEx.Code("(");
        for (var i = 0; i < _arguments.Length; i++)
        {
            if (i > 0)
                ConsoleEx.Code(", ");
            _arguments[i].Print();
        }

        ConsoleEx.Code(")");
    }
}